package com.xmutca.sso.manager;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xmutca.core.common.Receipt;
import com.xmutca.core.common.Result;
import com.xmutca.core.common.Results;
import com.xmutca.sso.api.Menu;
import com.xmutca.sso.api.manager.service.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-08-26 17:38
 */
@Controller
@RequestMapping("/menus")
public class MenuController {

    @Reference(version = "1.0.0", group = "sso", validation = "true")
    private MenuService menuService;

    /**
     * 菜单新增
     * @param menu
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public Receipt add(@ModelAttribute Menu menu) {
        return menuService.add(menu);
    }

    /**
     * 菜单删除
     * @param menuId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/{menuId}", method = RequestMethod.DELETE)
    public Receipt del(@PathVariable Integer menuId) {
        return menuService.del(menuId);
    }

    /**
     * 菜单批量删除
     * @param menuIds
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.DELETE)
    public Receipt batchDel(List<Integer> menuIds) {
        return menuService.batchDel(menuIds);
    }

    /**
     * 菜单更新
     * @param menu
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public Receipt update(@ModelAttribute Menu menu) {
        return menuService.update(menu);
    }

    /**
     * 菜单读取
     * @param menuId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/{menuId}", method = RequestMethod.GET)
    public Result<Menu> get(@PathVariable Integer menuId) {
        return menuService.get(menuId);
    }

    /**
     * 菜单查询r
     * @param current
     * @param pageSize
     * @param paramMap
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public Results<Menu> query(@RequestParam(required = false, defaultValue = "1") int current, @RequestParam(required = false, defaultValue = "20") Integer pageSize, @RequestParam Map<String, Object> paramMap) {
        return menuService.query(current, pageSize, paramMap);
    }
}
